package com.rainy.mod.plugin.common.util;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class StringUtils extends org.apache.commons.lang.StringUtils {
	
	private static String StringArray2Str(String[] values) {
		StringBuilder sb = new StringBuilder();
		for(String s : values) {
			sb.append(s);
		}
		
		return sb.toString();
	}
	
	/**
	 * 对Map中的对象根据MD5生成签名
	 * @param paramMap 参数map
	 * @param exceptParam 不参与生成签名的参数
	 * @param salt MD5签名用的盐值
	 * @return
	 */
	public static String generateMD5Sign(Map<String, Object> paramMap, String exceptParam, String salt) {
		List<String> source = new LinkedList<String>();
		StringBuilder sb = new StringBuilder();
		if(paramMap != null) {
			for(String key : paramMap.keySet()) {
				if(!key.equalsIgnoreCase(exceptParam)) {
					source.add(key + "=" + StringArray2Str((String[])paramMap.get(key)));
				}
			}
		}
		Collections.sort(source);
		for(String s : source) {
			sb.append(s);
		}
		
		return CryptUtils.encryptMD5(sb.toString(), salt);
	}

}
